home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libimp / impstat.c.z / impstat.c
C/C++ Source or Header  |  1996-05-06  |  5KB  |  195 lines

  1. /**************************************************************************
  2.  *
  3.  *           Copyright (c)    1993 Silicon Graphics, Inc.
  4.  *            All Rights Reserved
  5.  *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
  7.  *
  8.  * The copyright notice above does not evidence any actual of intended
  9.  * publication of such source code, and is an unpublished work by Silicon
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly
  13.  * prohibited.
  14.  *
  15.  * RESTRICTED RIGHTS LEGEND:
  16.  *
  17.  * Use, duplication or disclosure by the Government is subject to
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311
  24.  **************************************************************************
  25.  *
  26.  * File: impstat.c
  27.  *
  28.  * Description: Prints to stdout the SGI image header information found
  29.  *    in the specified image file(s).
  30.  *
  31.  *    Usage: imstat [-o offset] image ...
  32.  *
  33.  *    Where:
  34.  *
  35.  *    -o    Specifies an offset into the file where the SGI image
  36.  *        starts. Default is 0.
  37.  *
  38.  **************************************************************************/
  39.  
  40.  
  41. #ident "$Revision: 1.2 $"
  42.  
  43.  
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <sys/types.h>
  48. #include "imp.h"
  49.  
  50.  
  51. /* Local functions */
  52.  
  53. static void usage(char *progName);
  54.  
  55.  
  56. /**************************************************************************
  57.  *
  58.  * Function: main
  59.  *
  60.  * Description: Program entry point
  61.  *
  62.  * Parameters: 
  63.  *    argc (I) - number of command line arguments
  64.  *    argv (I) - command line arguments
  65.  *
  66.  * Return: 0 if no errors, 1 otherwise.
  67.  *
  68.  **************************************************************************/
  69.  
  70. int main(int argc, char *argv[])
  71. {
  72.     IMPImage *image;
  73.     register int i, ch;
  74.     char *fname, *pname;
  75.     off_t offset = 0;
  76.  
  77.     /*
  78.      * Extract the program basename
  79.      */
  80.     pname = ((pname = strrchr(argv[0], '/')) == NULL) ? argv[0]: pname + 1;
  81.  
  82.     /*
  83.      * Handle command line options
  84.      */
  85.     while ((ch = getopt(argc, argv, "o:")) != EOF) {
  86.         switch (ch) {
  87.             case 'o':
  88.                 offset = atoi(optarg);
  89.                 break;
  90.             case '?':
  91.             default:
  92.                 usage(pname);
  93.                 exit(1);
  94.         }
  95.     }
  96.  
  97.     /*
  98.      * Check the argument count
  99.      */
  100.     if (argc - optind < 1) {
  101.         usage(pname);
  102.         exit(1);
  103.     }
  104.  
  105.     /*
  106.      * Cycle through each image printing information
  107.      */
  108.     for (i = optind; i < argc; i++) {
  109.     /*
  110.      * Open the image for reading
  111.      */
  112.     if ((image = impOpenExt(argv[i], "r", offset, IMPNoCache)) == NULL) {
  113.         impPerror(pname);
  114.         exit(1);
  115.     }
  116.  
  117.     /*
  118.      * Extract the file's basename
  119.      */
  120.     fname = ((fname = strrchr(argv[i], '/')) == NULL) ? argv[i]: fname + 1;
  121.     
  122.     /*
  123.      * Print header information
  124.      */
  125.     printf("Filename:        %s\n", fname);
  126.     printf("Header Name:     '%s'\n", impName(image));
  127.     printf("X Size:          %d\n", impXSize(image));
  128.     printf("Y Size:          %d\n", impYSize(image));
  129.     printf("Num. Channels:   %d\n", impNumChannels(image));
  130.     printf("Dimension:       %d\n", impDimension(image));
  131.     printf("Min Value:       %d\n", impMinValue(image));
  132.     printf("Max Value:       %d\n", impMaxValue(image));
  133.     printf("Bytes Per Pixel: %d\n", impRasterBPP(image));
  134.     printf("Raster Encoding: %s\n",
  135.             (impRasterEncoding(image) == IMP_RASTER_ENC_RLE) ?
  136.             "RLE": "VERBATIM");
  137.     printf("Image Type:      ");
  138.     switch (impImageType(image)) {
  139.         case IMP_IMAGE_NORMAL:
  140.         printf("NORMAL\n");
  141.         break;
  142.         case IMP_IMAGE_DITHERED:
  143.         printf("DITHERED\n");
  144.         break;
  145.         case IMP_IMAGE_SCREEN:
  146.         printf("SCREEN\n");
  147.         break;
  148.         case IMP_IMAGE_COLORMAP:
  149.         printf("COLORMAP\n");
  150.         break;
  151.         default:
  152.         printf("%8X\n", impImageType(image));
  153.         break;
  154.     }
  155.     if (argc > 2)
  156.         printf("\n");
  157.  
  158.     /*
  159.      * Close the image
  160.      */
  161.     if (impClose(image) < 0) {
  162.         impPerror(pname);
  163.         exit(1);
  164.     }
  165.     }
  166.  
  167.     return 0;
  168. }
  169.  
  170.  
  171. /*
  172.  ==========================================================================
  173.                 LOCAL FUNCTIONS
  174.  ==========================================================================
  175. */
  176.  
  177.  
  178. /**************************************************************************
  179.  *
  180.  * Function: usage
  181.  *
  182.  * Description: Prints the program usage to stderr.
  183.  *
  184.  * Parameters: 
  185.  *    progName (I) - name of program
  186.  *
  187.  * Return: none
  188.  *
  189.  **************************************************************************/
  190.  
  191. static void usage(char *progName)
  192. {
  193.     fprintf(stderr, "Usage: %s [-o offset] image ...\n", progName);
  194. }
  195.